package com.chilly.jdkNio;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by Chilly Cui on 2020/12/28.
 */
public class FileOutputStreamDemo {
    public static void main(String[] args) throws Exception {
        FileOutputStream out = new FileOutputStream("test.txt");
        FileChannel outChannel = out.getChannel();

        ByteBuffer buffer = ByteBuffer.allocate(1024);
        //buffer.put("this is test content from fileOutputStream.".getBytes());
        for (int ii = 0; ii < 10; ++ii) {
            buffer.put("this is test content from fileOutputStream \r\n".getBytes("utf-8"));
        }
        buffer.flip();

        outChannel.write(buffer);

        out.close();
        outChannel.close();
    }
}
